package com.proyecto.poo;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CuadrilateroRes extends Activity {
	float base=0f;
    float altura=0f;
    float screenW,screenH,screenA;
	 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cuadresult);
        
        TextView texto = (TextView)findViewById(R.id.textView1);
        
        float area=0f;
        float perimetro=0f;
        String restext;
        
        base=0f;
        altura=0f;
        
        Bundle extras = getIntent().getExtras();
        if(extras !=null)
        {
         this.base = extras.getFloat("BaseCuadrilatero");
         this.altura = extras.getFloat("AlturaCuadrilatero");
        }
        
        area=base*altura;
        perimetro = (base*2)+(altura*2);
        restext="Area: "+Float.toString(area)+" Unidades\n"+"Perimetro: "+Float.toString(perimetro)+" Unidades";
        try{
        texto.setText(restext);
        }catch(Exception e){}       
        
        LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linearLayout1);
        Lienzo fondo=new Lienzo(this);        
        linearLayout.addView(fondo);
        screenW=linearLayout.getWidth();
        screenH=linearLayout.getHeight();
        screenA=screenW*screenH;
    }
    
    class Lienzo extends View {

        public Lienzo(Context context) {
            super(context);
        }
        
        protected void onDraw(Canvas canvas) {
            float proporcion=1;
        	if((base*altura)>240000)
            {
            	proporcion=(base*altura)/240000;
            }
        	
            Paint pincel1=new Paint();
            pincel1.setStrokeWidth(3);
            pincel1.setARGB(130,116,183,252);
       
            
            pincel1.setStrokeWidth(80);
            
            canvas.drawRect(50, 50, 50+base/proporcion, 50+altura/proporcion, pincel1);
            pincel1.setARGB(255,255,255,255);
            pincel1.setTextSize(15);
            canvas.drawText(""+base+" Unidades", (50+base/2)/proporcion, 45, pincel1);
            canvas.drawText(""+altura+" Unidades", (base+55)/proporcion, 45+altura/2, pincel1);
        }
    }    

}
